<?php

hc_core_ClassLoader::load('substrate_Context');

class substrate_ContextUtil {
    public static function findObjectsByImplementation(substrate_IContext $context, $classOrInterface) {
        $map = $context->getRegisteredObjectImplementationMap();
        if ( isset($map[$classOrInterface]) ) {
            $objects = array();
            foreach ( $map[$classOrInterface] as $name ) {
                $objects[] = $context->get($name);
            }
            return $objects;
        }
        return array();
    }
    public static function findObjectByImplementation(substrate_IContext $context, $classOrInterface, $exceptionOnMultiple = false) {
        $objects = self::findObjectsByImplementation($context, $classOrInterface);
        if ( count($objects) < 1 ) return null;
        if ( count($objects) > 1 and $exceptionOnMultiple ) {
            throw new Exception('Multiple implementations of "' . $classOrInterface . '" found.');
        }
        return $objects[0];
    }
}

?>
